package com.alks.function.mapper;

import com.alks.common.data.dto.SysUserTokenDTO;
import com.alks.entity.data.entity.*;
import com.alks.entity.data.entity.excel.PcOrderPlanExcel;
import com.alks.function.data.request.prod.ProdDynamicDetailRequest;
import com.alks.function.data.request.prod.ProdDynamicRequest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface ProdDynamicHeadMapper extends BaseMapper<ProdDynamicHeadRep> {
    List<String> getStyles();

    List<String> getBrands();

    List<String> getSeasons();

    List<String> getSamples();

    List<String> getPurType();

    List<Map<String,String>> getVendors();

    List<String> getSysUser();

    List<ProdDynamicHeadRep> getPcProdDynamicList(ProdDynamicRequest request);

    Long getPcProdDynamicTotal(ProdDynamicRequest request);

    List<PcProdDynamicDetail> getProdDynamicDetail(ProdDynamicDetailRequest request);

    BigDecimal getPcProdDynamicQtyTotal(ProdDynamicRequest request);

    @Select("SELECT DISTINCT ORDER_ID FROM PC_MTL_PRE_OTHER WHERE PUR_NO IS  NULL ")
    List<String> getProdDynamicPurs();

    @Select("SELECT DISTINCT ORDER_ID FROM PC_PUR_DETAIL WHERE IN_QTY IS NULL")
    List<String> getProdDynamicIns();

    List<PcProdOrderRep> getPreOrderList(PcProdPreReq req);

    BigDecimal getPreOrderPreQtys(PcProdPreReq req);

    void updateLotOver(@Param("list") List<String> list);

    Integer selectByLots( String orderId);

    void updateLotRecover(List<String> list);

    List<PcScheduleRep1> getPcScheduleList(@Param("lotNo") String lotNo,@Param("shoeName") String shoeName);

    BigDecimal getPcScheduleListSchTotal(@Param("lotNo") String lotNo,@Param("shoeName") String shoeName);

    BigDecimal getPcScheduleProdTotal(@Param("lotNo") String lotNo,@Param("shoeName") String shoeName);

    @Select("SELECT COUNT(*) FROM PC_SCHEDULE_HEAD WHERE SCHEDULE_NO = #{format}")
    Integer getCurrentList(String format);

    void insertIntoPcSch(@Param("list") List<PcScheduleRep1> list , @Param("format") String format, @Param("stkQty") BigDecimal stkQty);

    @Update("UPDATE PC_SCHEDULE_HEAD SET PROD_DAYS = NULL ,END_DATE = NULL ,DELIVERY_DATE = NULL WHERE SCHEDULE_NO = #{format}")
    void setEmptyPcSch(String format);

    void insertIntoPcSchByHead(@Param("list") List<String> list);

    void deleteByLotNos(List<String> list);

    List<PcScheduleRep1> getPcScheduleList1(String order);


    @Delete("DELETE FROM PC_SCHEDULE_HEAD WHERE SCHEDULE_NO = DATE_FORMAT(now(),'%Y%m%d')")
    void deleteSchNo();

    void insertIntoList(List<PcScheduleRep1> list);


    void up(List<PcScheduleRep1> list);

    void down(PcScheduleRep1 req);

    void insertByFinalList(@Param("list") List<PcScheduleRep1> finalList);

    List<PcScheduleRep1> getPcSchList();

    List<MtlDPlanArrangeRep> arrangePlanList(@Param("plan") String plan,@Param("req") PcProdArrangeReq req);

    List<PcStitchPlanRep> arrangePlanListStitch(@Param("plan") String plan,@Param("req") PcProdArrangeReq req);

    List<MtlDPlanArrangeRep> choosePlanList(@Param("req") PcProdArrangeReq req);

    void insertIntoPcPlan(@Param("list") List<String> list, @Param("choose") String choose);

    void updatePcOrderPlan(@Param("req") MtlDPlanArrangeRep req, @Param("choose") String choose);

    void removePcOrderPlan(@Param("req") MtlDPlanArrangeRep req, @Param("choose") String choose);

    List<PcCutProdStatusRep> cutProdStatusList(@Param("date") String date, @Param("choose") String choose);

    Integer insertProdStatus(PcCutProdStatusRep req);

    @Delete("DELETE FROM PC_PROD_TOTAL_MONTH_KF WHERE SEQ_NO = NULLIF(#{seqNo},NULL) AND `MONTH` = NULLIF(#{month},'') AND DEPT_NO = NULLIF(#{deptNo},'') LIMIT 1")
    Integer deleteByProdStatus(PcCutProdStatusRep req);

    Integer updateByProdStatus(PcCutProdStatusRep req);

    List<MtlDPlanArrangeRep> devPartDayPlanList(PcDevPartDayPlanReq req);

    Integer updatePartDayPlan(MtlDPlanArrangeRep req);

    @Delete("DELETE FROM PC_ORDER_PLAN_DAY WHERE ORDER_ID = #{lotNo} AND PLAN_TYPE = #{line} ")
    void deletePartDayPlan(MtlDPlanArrangeRep req);

    @Select("SELECT DISTINCT CAST(SEQ_NO AS DECIMAL(10,2)) seqNo,PLAN_TYPE planType FROM PC_ORDER_PLAN_DAY ORDER BY SEQ_NO")
    List<Map<String, Object>> getLine();

    String getEndDateMtl(PcProdArrangeReq req,@Param("mtl") String mtl);

    Integer insertIntoPcOrderPlan(@Param("re") PcOrderPlanExcel re, @Param("companyId") String companyId);

    List<PcScheduleRep1> getPcScheduleList2(String format);

    List<String> getOrderIdByProd(List<PcScheduleRep1> list);

    List<String> getUpdateLotByOrderHead();

    void insertIntoPcOrderLot(@Param("orderIds") List<String> orderIds, @Param("dto") SysUserTokenDTO dto);

    void updatePcSchLot(List<String> list);

    BigDecimal getOrderQty(List<String> list);


    List<Map<String, Object>> getPcOrderSch();

    @Select("SELECT MAX( SCHEDULE_NO ) FROM PC_SCHEDULE_HEAD WHERE begin_date IS NOT NULL")
    String getScheduleNo();

    void deleteUp(List<PcScheduleRep1> req);

    void updateSeq(@Param("scheduleNo") String scheduleNo, @Param("subtract") BigDecimal subtract, @Param("size") int size);

    void updateSeq1(@Param("scheduleNo") String scheduleNo, @Param("seqNo1") BigDecimal seqNo1, @Param("size") int size);

    List<Map<String, Object>> getLine1(String companyId);


    void updatePcLine1(Map<String, Object> map);

    Integer getStdQty(String companyId);
}
